#pragma once
#include <iostream>
#include <string>
#include <functional>
#include <cstdio>

// typedef std::function<void* (void*)> fun_t;
// typedef void *(*fun_t)(void *);
using fun_t = void *(*)(void *);
class ThreadInfo
{
public:
    std::string _threadName;
    void *_ptrSocketFd;// 在线程池中该指针指向线程池对象 此处指向socketfd
};

class Thread
{
public:
    Thread(int index, fun_t startRoutine, void *ptrTofd)
        : _startRoutine(startRoutine)
    {
        char nameBuf[64];
        snprintf(nameBuf, sizeof nameBuf, "Thread-%d", index);
        _name = nameBuf;

        _tInfo._threadName = _name;
        _tInfo._ptrSocketFd = ptrTofd;
    }

    void start()
    {
        pthread_create(&_tid, nullptr, _startRoutine, (void *)&_tInfo);
    }

    void join()
    {
        pthread_join(_tid, nullptr);
    }
    std::string getThreadName()
    {
        return _name;
    }
    ~Thread()
    {
    }

private:
    pthread_t _tid;
    std::string _name;
    fun_t _startRoutine;
    ThreadInfo _tInfo;
};